import React, {Component} from 'react';
import {Grid,Search, Button} from '@icedesign/base';
import {
  FormBinderWrapper as IceFormBinderWrapper,
  FormBinder as IceFormBinder,
  FormError as IceFormError,
} from '@icedesign/form-binder';
import API from '../../../../../../tools/API';

const {Row, Col} = Grid;
/**
*  用户列表查询
*/
export default class QueryDict extends Component{
   constructor(props) {
     super(props);
     this.state = {
       dataSource: [
         {
           label: "全部",
           value: "",
           filterValue:1,
           disabled: false
         }
       ],
     };
   }

   //初始化
   componentWillMount(){
     //获取当前登录用户信息
     API.getQueryItem({parent_id:this.props.parentId}).then((res) => {
       res.result.forEach(item =>{
         this.state.dataSource.push({
           label: item,
           value: item,
           disabled: false
         });
         this.setState(this.state);
       })
     })
   }

   //调用查询
   onSearch(obj) {
     let json = {
       parent_id:this.props.parentId
     }
     //设置查询参数
     if (obj.key == '全部') {
       json = {};
     } else{
       if(obj.key != ""){
         json['key'] = obj.key;
       }
     }
     // this.state.value = obj.key;
     // this.setState(this.state);
     console.log(json);
     this.props.updateQuery(json);
   }

  render(){
    return(
      <div>
        <IceFormBinderWrapper
          value={this.state}
          ref="form">
            <Row wrap={true} gutter={20}>
              <Col span='24'>
                <Search
                  inputWidth={180}
                  onSearch={this.onSearch.bind(this)}
                  dataSource={this.state.dataSource}
                  placeholder="搜索"
                  searchText=""
                  name="textName"
                  className="search-style"
                />
              </Col>
            </Row>
        </IceFormBinderWrapper>
      </div>
    )
  }
}
